package cn.dankal.flyaudio.personal.setting;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

import com.alibaba.android.arouter.facade.annotation.Route;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.dankal.basiclib.base.activity.BaseActivity;
import cn.dankal.basiclib.base.activity.BaseStateActivity;
import cn.dankal.basiclib.protocol.PersonalProtocol;
import cn.dankal.basiclib.util.WebViewUtil;
import cn.dankal.basiclib.widget.DKWebView;
import cn.dankal.basiclib.widget.TipDialog;
import cn.dankal.business.pojo.NotificationBean;
import cn.dankal.flyaudio.R;
import cn.dankal.flyaudio.personal.notificaiton.SettingPresenter;

/**
 * @author vane
 * @since 2018/8/20
 */
@Route(path = PersonalProtocol.ABOUT_US)
public class AboutUsActivity extends BaseStateActivity implements SettingContract.View {


    @BindView(R.id.wb)
    DKWebView wb;
    private SettingPresenter settingPresenter;
    private int msgType = SettingContract.MsgType.about_me;

    @Override
    public void render(NotificationBean t) {
        if (t != null) {
            WebViewUtil.initWebViewSettings(wb, this);
            wb.setWebViewClient(new WebViewUtil.MyWebViewClient());
            WebViewUtil.loadData(wb, t.content);
            wb.setVisibility(View.GONE);
            showLoadingDialog();
            wb.setWebChromeClient(new WebChromeClient() {
                public void onProgressChanged(WebView view, final int progress) {
                    if (progress == 100) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(800);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (loadingDialog != null && loadingDialog.isShowing()) {
                                            loadingDialog.dismiss();
                                        }
                                        wb.setVisibility(View.VISIBLE);
                                    }
                                });
                            }
                        }).start();
                    }
                }
            });
        }
    }

    @Override
    public Object contentView() {
        return null;
    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_base_webview;
    }

    @Override
    protected void initComponents() {
        addSingleTitleBar("关于我们");
        settingPresenter = new SettingPresenter(msgType);
        settingPresenter.attachView(this);
        settingPresenter.requestData();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }


}

